<template>
  <div class="header-wrapper">
    <!-- <label>时间维度</label>
    <px-radio-group v-model="dateType">
      <px-radio :label="1">日</px-radio>
      <px-radio :label="2">月</px-radio>
      <px-radio :label="3">年</px-radio>
    </px-radio-group> -->
    <px-date-picker
      v-model="dateRange"
      value-format="YYYY-MM-DD"
      type="daterange"
      range-separator=" - "
      start-placeholder="开始时间"
      end-placeholder="结束时间"
    />
  </div>
  <algorithmLifeCyclePredict :date="dateRange"></algorithmLifeCyclePredict>
</template>
<script lang="ts" setup>
import { ref, onMounted } from "vue";
import algorithmLifeCyclePredict from "./algorithmLifeCyclePredict.vue";

const dateType = ref("day");
const dateRange = ref([]);

onMounted(() => {
  initQuery();
});

const initQuery = () => {
  dateRange.value = [getCurrentMonthF(), getCurrentMonthL()];
};

// 获取当月第一天
const getCurrentMonthF = () => {
  let date = new Date();
  let y = date.getFullYear(); // 获取年
  let m: any = date.getMonth() + 1; // 获取月
  let d = "01";
  m = m < 10 ? "0" + m : m;
  return [y, m, d].join("-");
};

// 获取当月最后一天
const getCurrentMonthL = () => {
  let date = new Date();
  let y = date.getFullYear(); // 获取年
  let m: any = date.getMonth() + 1; // 获取月
  let d: any = new Date(y, m, 0).getDate();
  m = m < 10 ? "0" + m : m;
  d = d < 10 ? "0" + d : d;
  return [y, m, d].join("-");
};
</script>
<style lang="scss" scoped>
.header-wrapper {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
  align-items: center;
  label {
    font-size: 14px;
    color: #333;
    font-weight: 400;
  }
  :deep(.px-date-editor) {
    max-width: 240px;
  }
}
</style>
